<?php
/**
 * 应用自定义控制器类
 * 
 * @version $Id: UserController.php 291 2012-05-04 03:01:07Z linsir123 $
 */
class UserController extends AppController  
{
	/**
	 * 控制器前置操作
	 */
	public function beforeAction()
	{
		if ( ! M::user()->isLogin()) 
			$this->r();
		
		///
		UserView::init();
		
		///
		App::getView()->conf['caching'] = 0;
	}
	
	/**
	 * 路由跳转
	 */
	public function r($r = '', $return = false)
	{
		$r = 'user/'.$r;
		if ($return) 
			return lpUrl::__($r);
			
		///
		lpUrl::_r($r);
	}
	
	/**
	 * 输出分页
	 */
	public function pagination($show, $count, $r)
	{
		$totalPage = ceil($count/$show);
		$page = intval($_GET['p']);
		if ($page <= 0) 
			$page = 1;
		if ($page >= $totalPage)
			$page = $totalPage;
			
		///
		$terms = array('first'=>'首页','pre'=>'上一页','next'=>'下一页','last'=>'尾页');
		$com = App::C('Pagination', null, $page, $totalPage, 8, $terms);
		$com->setAformat("<a url=\"". $this->r($r.'/p/%d', true) ."\" class=\"\">%s</a>");
		$pagination = $com->display();
		
		///
		View::assign('pagination', $pagination);
		View::assign('baseNum', ($page-1)*$show);
		return $page;
	}
}
